package priv.yiyuan.example.design.flyweight;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class CharacterFormatFactory {

    private static final Map<String, CharacterFormat> formatCache = new HashMap<>();

    public static CharacterFormat getCharacterFormat(String fontName, int fontSize, Color color, boolean bold, boolean italic) {
        String key = fontName + "-" + fontSize + "-" + color.getRGB() + "-" + bold + "-" + italic;

        CharacterFormat format = formatCache.get(key);

        if (format == null) {
            format = new CharacterFormat(fontName, fontSize, color, bold, italic);
            formatCache.put(key, format);
        }

        return format;
    }

    public static int getCacheSize(){
        return formatCache.size();
    }

}
